<template>
  <div class="student-body syllabus_jd">
    <h2 class="box_tit">
      <i class="icon icon1"></i>添加课程进度
      <i class="reti" style="width:150px"></i>
    </h2>
    <div class="blank20"></div>
        <!-- 页面编辑页*****开始 -->
        <div class="goBack">
            <a href="JavaScript:void(0);" class="btns" @click="goBack">返回上一级</a>
        </div>
      <div  class="editbox"   >
    <h2 class="second_menu">基本信息</h2>
    <el-form :model="params" label-width="100px" class="demo-ruleForm">
      <el-row>
        <el-col>
          <el-col :span="6">
            <el-form-item label="院校">
              <el-input v-model="params.schoolName" disabled="disabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="二级学院" >
              <el-input v-model="params.secondSchoolName" disabled="disabled"></el-input>
            </el-form-item>
          </el-col>
        </el-col>
      </el-row>

      <el-row>
        <el-col >
          <el-col :span="6">
            <el-form-item label="专业">
              <el-input v-model="params.professionName" disabled="disabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="班级">
              <el-input v-model="params.classesNames" disabled="disabled"></el-input>
            </el-form-item>
          </el-col>
        </el-col>
      </el-row>

      <el-row>
        <el-col>
          <el-col :span="6">
            <el-form-item label="课程名">
              <el-input v-model="params.courseName" disabled="disabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="授课日期">
              <el-input v-model="params.teachDate" disabled="disabled"></el-input>
            </el-form-item>
          </el-col>
        </el-col>
      </el-row>

      <el-row>
        <el-col>
          <el-col :span="6">
            <el-form-item label="授课节次">
              <el-input v-model="params.section" disabled="disabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="授课地点">
              <el-input v-model="params.teachPlace" disabled="disabled"></el-input>
            </el-form-item>
          </el-col>
        </el-col>
      </el-row>
      </el-form>

      <el-form :model="addBean" :rules="rules" ref="addBean" label-width="100px" class="demo-ruleForm">
      <h2 class="second_menu">授课内容</h2>
      <el-row>
        <el-col :span="14">
          <el-form-item label="内容" prop="teachContent" >
            <el-input type="textarea" v-model="addBean.teachContent"></el-input>
          </el-form-item>
        </el-col>
      </el-row>


      <h2 class="second_menu">课堂效果</h2>
      <el-row>
        <el-col :span="14">
          <el-form-item label="优势点" prop="teachPositiveEffect">
            <el-input type="textarea" v-model="addBean.teachPositiveEffect" ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
          <el-col :span="14">
            <el-form-item label="欠缺点" prop="teachNegativeEffect">
              <el-input type="textarea" v-model="addBean.teachNegativeEffect" ></el-input>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row>
        <el-col :span="14">
          <el-form-item label="改进方案" prop="teachImprovementScheme">
            <el-input type="textarea" v-model="addBean.teachImprovementScheme"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    </div>
    <div class="center">
        <el-button class="btns" type="primary" size="mini" @click="submitForm('addBean')" >保存</el-button>
        <el-button class="btns cancel" @click="resetForm('addBean')" size="mini" >重置</el-button>
      </div>
  </div>
</template>
<script>
  import ElCol from "element-ui/packages/col/src/col";
  export default {
    components: {ElCol},
    data() {
      return {
        id:null,
        params:{
          schoolName:null,
          secondSchoolName:null,
          professionName:null,
          classesNames:null,
          courseName:null,
          teachDate:null,
          section:null,
          teachPlace:null
        },
        addBean: {
          teachContent:null,
          teachPositiveEffect:null,
          teachNegativeEffect:null,
          teachImprovementScheme:null
        },
        noEditable:false, // 是详情页true  还是已修改页false
        rules: {
          teachContent: [
            { required: true, message: '请填写授课内容', trigger: 'blur' },
            { min: 2, max: 1000, message: '长度在 2 到 500 个字符', trigger: 'blur' }
          ],
          teachPositiveEffect: [
            { required: true, message: '请填写优势点', trigger: 'blur' },
            { min: 2, max: 500, message: '长度在 2 到 500 个字符', trigger: 'blur' }
          ],
          teachNegativeEffect: [
            { required: true, message: '请填写欠缺点', trigger: 'blur' },
            { min: 2, max: 500, message: '长度在 2 到 500 个字符', trigger: 'blur' }
          ],
          teachImprovementScheme: [
            { required: true, message: '请填写改进方案', trigger: 'blur' },
            { min: 2, max: 500, message: '长度在 2 到 500 个字符', trigger: 'blur' }
          ]
        }
      };
    },
    created(){
      var self = this;
      self.id = self.$route.params.id;
      self.axios({
                    method:"get",
                    url:api.getTeacherWorkProgressDetailById+self.id,
                }).then(function (response) {
                  // console.log(JSON.stringify(response));
                  if(response.data.success){
                    let params = response.data.data;
                    self.params.schoolName = params.schoolName;
                    self.params.secondSchoolName = params.secondSchoolName;
                    self.params.professionName = params.professionName;
                    self.params.classesNames = params.classesNames;
                    self.params.courseName = params.courseName;
                    self.params.teachDate = params.teachDate;
                    self.params.section = "第"+params.section+"节";
                    self.params.teachPlace = params.teachPlace;

                    self.addBean.teachContent = params.teachContent;
                    self.addBean.teachPositiveEffect = params.teachPositiveEffect;
                    self.addBean.teachNegativeEffect = params.teachNegativeEffect;
                    self.addBean.teachImprovementScheme = params.teachImprovementScheme;
                  }
                });
    },
    methods: {
      submitForm(addBean) {
        var self = this;
        this.$refs[addBean].validate((valid) => {
          if (valid) {
            self.addBean.lessonId = self.params.lessonId;
            this.saveFeedback();
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(addBean) {
        this.$refs[addBean].resetFields();
      },
      saveFeedback(){

        let self = this;
        // console.log(JSON.stringify(self.addBean));
        // return;
        self.axios({
              method: 'post',
              url: api.updateTeacherWorkProgress+'?lessonId='+self.id+'&teachContent='+self.addBean.teachContent+'&teachPositiveEffect='+self.addBean.teachPositiveEffect+'&teachNegativeEffect='+self.addBean.teachNegativeEffect+'&teachImprovementScheme='+self.addBean.teachImprovementScheme,
            }).then(function(response){
              if(response.data.success){
                self.$message({
                  message: '保存成功',
                  type: 'success'
                });
                setTimeout(()=>{
                  self.$router.push({
                    name:'FeedbackList'
                  })
                },1000);
              }else{
                self.$message({
                  message: response.msg,
                  type: 'error'
                });
              }
            });
      },
      //返回上一层
      goBack(){
        this.$router.go(-1);
      }
    }
  }
</script>

<style scoped>
  .demo-ruleForm{
    width:1000px;
  }
  .center{
    width:500px;
    text-align: center;
    margin: 20px 0;
  }
  .second_menu{
    color:#409EFF;
    border-bottom: 1px solid #e6e8ec;
    padding-top:5px;
    padding-bottom : 5;
    width: 800px;
    margin-bottom: 10px;
  }
  .goBack{
    text-align: right;
}
  .student-body {
    min-height: 545px;
    width: 100%;
    background: #fff;
    border-radius: 4px;
    padding: 15px;
  }
  .student-body .contents span {
    display: inline-block;
    width: 100px;
    margin-top: 10px;
    text-align: right;
  }
  .student-body .contents .spanInput {
    height: 26px;
    width: 206px;
    line-height: 26px;
    font-size: 12px;
    color: #cdcdcd;
    text-indent: 5px;
    border-radius: 15px;
    border: 1px solid #cdcdcd;
    box-sizing: border-box;
    outline: none;
  }

  .student-body .contents .sexSpan {
    width: 20px;
    padding-left: 20px;
  }
  .student-body .contents .sexSpans{
    width: 50px;
  }
  .student-body .contents .lableInput {
    position: absolute;
    top: 12px;
    left: 105px;
  }
  .student-body .contents
  .student-body .reti {
    width: 94px;
  }
  .student-body .inputs {
    width: 100%;
    height: 40px;
    padding-top: 20px;
  }
  .student-body .inputs > span {
    font-size: 12px;
    color: #333;
    padding-left: 1px;
  }

  .box_tit {
    border-bottom: 1px solid #e6e8ec;
    position: relative;
    padding: 4px 0 10px 30px;
    margin-top: 0;
    font-weight: bold;
    line-height: 16px;
  }

</style>
